package com.fjp.heartguard.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.fjp.heartguard.app.base.HTBaseViewModel
import com.fjp.heartguard.app.data.bean.SaveQuestionResult
import com.fjp.heartguard.app.network.HttpRequestCoroutine
import com.fjp.heartguard.ui.question.QuestionActivity
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.ext.requestNoCheck
import me.hgj.jetpackmvvm.state.ResultState
import okhttp3.MultipartBody

/**
 *Author:Mr'x
 *Time:2025/2/6
 *Description:
 */
class QuestionSupplementaryInfoViewModel : HTBaseViewModel() {
    val date = ObservableField<String>("")
    val supplementaryInfo = ObservableField<String>("")
    var commitLiveData = MutableLiveData<ResultState<SaveQuestionResult>>()
    var recordUpdateFailed = MutableLiveData<Boolean>()
    var recordUpdateSuccess = MutableLiveData<Boolean>()

    fun saveQuestionnaireInfo() {
        request({
            HttpRequestCoroutine.saveQuestionnaireInfo(QuestionActivity.olderInfo)
        }, commitLiveData, true,"正在保存测评信息...")

    }

    fun updateRecord(body: MultipartBody.Part) {
        requestNoCheck({ HttpRequestCoroutine.uploadImg(body) }, {
            //请求成功 自己拿到数据做业务需求操作
            if (it.status == "success") {
                QuestionActivity.olderInfo.audio_file = it.data
                recordUpdateSuccess.postValue(true)
            } else {
                recordUpdateFailed.postValue(true)
            }
        }, {
            recordUpdateFailed.postValue(true)
        }, true, "正在上传录音...")
    }

}